/**
 * 
 */
package us.levk.remote.drmaa.client.impl;

import java.net.URL;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.UUID;

import org.ggf.drmaa.DrmaaException;
import org.ggf.drmaa.FileTransferMode;
import org.ggf.drmaa.JobTemplate;
import org.ggf.drmaa.PartialTimestamp;

import us.levk.remote.drmaa.common.api.RemoteTemplate;


/**
 * @author levk
 *
 */
public class JobTemplateImpl implements JobTemplate {

  final transient Map<URL, Map<Class<?>, Object>> remote;
  final UUID template;
  final URL url;

  JobTemplateImpl (Map<URL, Map<Class<?>, Object>> remote, UUID template, URL url) {
    this.template = template;
    this.url = url;
    this.remote = remote;
  }

  /* (non-Javadoc)
   * @see org.ggf.drmaa.JobTemplate#setRemoteCommand(java.lang.String)
   */
  @Override public void setRemoteCommand (String remoteCommand) throws DrmaaException {
    ((RemoteTemplate) remote.get (url).get (RemoteTemplate.class)).setRemoteCommand (template, remoteCommand);
  }

  /* (non-Javadoc)
   * @see org.ggf.drmaa.JobTemplate#getRemoteCommand()
   */
  @Override public String getRemoteCommand () throws DrmaaException {
    return ((RemoteTemplate) remote.get (url).get (RemoteTemplate.class)).getRemoteCommand (template);
  }

  /* (non-Javadoc)
   * @see org.ggf.drmaa.JobTemplate#setArgs(java.util.List)
   */
  @SuppressWarnings ("rawtypes") @Override public void setArgs (List args) throws DrmaaException {
    ((RemoteTemplate) remote.get (url).get (RemoteTemplate.class)).setArgs (template, args);
  }

  /* (non-Javadoc)
   * @see org.ggf.drmaa.JobTemplate#getArgs()
   */
  @SuppressWarnings ("rawtypes") @Override public List getArgs () throws DrmaaException {
    return ((RemoteTemplate) remote.get (url).get (RemoteTemplate.class)).getArgs (template);
  }

  /* (non-Javadoc)
   * @see org.ggf.drmaa.JobTemplate#setJobSubmissionState(int)
   */
  @Override public void setJobSubmissionState (int state) throws DrmaaException {
    ((RemoteTemplate) remote.get (url).get (RemoteTemplate.class)).setJobSubmissionState (template, state);
  }

  /* (non-Javadoc)
   * @see org.ggf.drmaa.JobTemplate#getJobSubmissionState()
   */
  @Override public int getJobSubmissionState () throws DrmaaException {
    return ((RemoteTemplate) remote.get (url).get (RemoteTemplate.class)).getJobSubmissionState (template);
  }

  /* (non-Javadoc)
   * @see org.ggf.drmaa.JobTemplate#setJobEnvironment(java.util.Map)
   */
  @SuppressWarnings ("rawtypes") @Override public void setJobEnvironment (Map env) throws DrmaaException {
    ((RemoteTemplate) remote.get (url).get (RemoteTemplate.class)).setJobEnvironment (template, env);
  }

  /* (non-Javadoc)
   * @see org.ggf.drmaa.JobTemplate#getJobEnvironment()
   */
  @SuppressWarnings ("rawtypes") @Override public Map getJobEnvironment () throws DrmaaException {
    return ((RemoteTemplate) remote.get (url).get (RemoteTemplate.class)).getJobEnvironment (template);
  }

  /* (non-Javadoc)
   * @see org.ggf.drmaa.JobTemplate#setWorkingDirectory(java.lang.String)
   */
  @Override public void setWorkingDirectory (String wd) throws DrmaaException {
    ((RemoteTemplate) remote.get (url).get (RemoteTemplate.class)).setWorkingDirectory (template, wd);
  }

  /* (non-Javadoc)
   * @see org.ggf.drmaa.JobTemplate#getWorkingDirectory()
   */
  @Override public String getWorkingDirectory () throws DrmaaException {
    return ((RemoteTemplate) remote.get (url).get (RemoteTemplate.class)).getWorkingDirectory (template);
  }

  /* (non-Javadoc)
   * @see org.ggf.drmaa.JobTemplate#setJobCategory(java.lang.String)
   */
  @Override public void setJobCategory (String category) throws DrmaaException {
    ((RemoteTemplate) remote.get (url).get (RemoteTemplate.class)).setJobCategory (template, category);
  }

  /* (non-Javadoc)
   * @see org.ggf.drmaa.JobTemplate#getJobCategory()
   */
  @Override public String getJobCategory () throws DrmaaException {
    return ((RemoteTemplate) remote.get (url).get (RemoteTemplate.class)).getJobCategory (template);
  }

  /* (non-Javadoc)
   * @see org.ggf.drmaa.JobTemplate#setNativeSpecification(java.lang.String)
   */
  @Override public void setNativeSpecification (String spec) throws DrmaaException {
    ((RemoteTemplate) remote.get (url).get (RemoteTemplate.class)).setNativeSpecification (template, spec);
  }

  /* (non-Javadoc)
   * @see org.ggf.drmaa.JobTemplate#getNativeSpecification()
   */
  @Override public String getNativeSpecification () throws DrmaaException {
    return ((RemoteTemplate) remote.get (url).get (RemoteTemplate.class)).getNativeSpecification (template);
  }

  /* (non-Javadoc)
   * @see org.ggf.drmaa.JobTemplate#setEmail(java.util.Set)
   */
  @SuppressWarnings ("rawtypes") @Override public void setEmail (Set email) throws DrmaaException {
    ((RemoteTemplate) remote.get (url).get (RemoteTemplate.class)).setEmail (template, email);
  }

  /* (non-Javadoc)
   * @see org.ggf.drmaa.JobTemplate#getEmail()
   */
  @SuppressWarnings ("rawtypes") @Override public Set getEmail () throws DrmaaException {
    return ((RemoteTemplate) remote.get (url).get (RemoteTemplate.class)).getEmail (template);
  }

  /* (non-Javadoc)
   * @see org.ggf.drmaa.JobTemplate#setBlockEmail(boolean)
   */
  @Override public void setBlockEmail (boolean blockEmail) throws DrmaaException {
    ((RemoteTemplate) remote.get (url).get (RemoteTemplate.class)).setBlockEmail (template, blockEmail);
  }

  /* (non-Javadoc)
   * @see org.ggf.drmaa.JobTemplate#getBlockEmail()
   */
  @Override public boolean getBlockEmail () throws DrmaaException {
    return ((RemoteTemplate) remote.get (url).get (RemoteTemplate.class)).getBlockEmail (template);
  }

  /* (non-Javadoc)
   * @see org.ggf.drmaa.JobTemplate#setStartTime(org.ggf.drmaa.PartialTimestamp)
   */
  @Override public void setStartTime (PartialTimestamp startTime) throws DrmaaException {
    ((RemoteTemplate) remote.get (url).get (RemoteTemplate.class)).setStartTime (template, startTime);
  }

  /* (non-Javadoc)
   * @see org.ggf.drmaa.JobTemplate#getStartTime()
   */
  @Override public PartialTimestamp getStartTime () throws DrmaaException {
    return ((RemoteTemplate) remote.get (url).get (RemoteTemplate.class)).getStartTime (template);
  }

  /* (non-Javadoc)
   * @see org.ggf.drmaa.JobTemplate#setJobName(java.lang.String)
   */
  @Override public void setJobName (String name) throws DrmaaException {
    ((RemoteTemplate) remote.get (url).get (RemoteTemplate.class)).setJobName (template, name);
  }

  /* (non-Javadoc)
   * @see org.ggf.drmaa.JobTemplate#getJobName()
   */
  @Override public String getJobName () throws DrmaaException {
    return ((RemoteTemplate) remote.get (url).get (RemoteTemplate.class)).getJobName (template);
  }

  /* (non-Javadoc)
   * @see org.ggf.drmaa.JobTemplate#setInputPath(java.lang.String)
   */
  @Override public void setInputPath (String inputPath) throws DrmaaException {
    ((RemoteTemplate) remote.get (url).get (RemoteTemplate.class)).setInputPath (template, inputPath);
  }

  /* (non-Javadoc)
   * @see org.ggf.drmaa.JobTemplate#getInputPath()
   */
  @Override public String getInputPath () throws DrmaaException {
    return ((RemoteTemplate) remote.get (url).get (RemoteTemplate.class)).getInputPath (template);
  }

  /* (non-Javadoc)
   * @see org.ggf.drmaa.JobTemplate#setOutputPath(java.lang.String)
   */
  @Override public void setOutputPath (String outputPath) throws DrmaaException {
    ((RemoteTemplate) remote.get (url).get (RemoteTemplate.class)).setOutputPath (template, outputPath);
  }

  /* (non-Javadoc)
   * @see org.ggf.drmaa.JobTemplate#getOutputPath()
   */
  @Override public String getOutputPath () throws DrmaaException {
    return ((RemoteTemplate) remote.get (url).get (RemoteTemplate.class)).getOutputPath (template);
  }

  /* (non-Javadoc)
   * @see org.ggf.drmaa.JobTemplate#setErrorPath(java.lang.String)
   */
  @Override public void setErrorPath (String errorPath) throws DrmaaException {
    ((RemoteTemplate) remote.get (url).get (RemoteTemplate.class)).setErrorPath (template, errorPath);
  }

  /* (non-Javadoc)
   * @see org.ggf.drmaa.JobTemplate#getErrorPath()
   */
  @Override public String getErrorPath () throws DrmaaException {
    return ((RemoteTemplate) remote.get (url).get (RemoteTemplate.class)).getErrorPath (template);
  }

  /* (non-Javadoc)
   * @see org.ggf.drmaa.JobTemplate#setJoinFiles(boolean)
   */
  @Override public void setJoinFiles (boolean join) throws DrmaaException {
    ((RemoteTemplate) remote.get (url).get (RemoteTemplate.class)).setJoinFiles (template, join);
  }

  /* (non-Javadoc)
   * @see org.ggf.drmaa.JobTemplate#getJoinFiles()
   */
  @Override public boolean getJoinFiles () throws DrmaaException {
    return ((RemoteTemplate) remote.get (url).get (RemoteTemplate.class)).getJoinFiles (template);
  }

  /* (non-Javadoc)
   * @see org.ggf.drmaa.JobTemplate#setTransferFiles(org.ggf.drmaa.FileTransferMode)
   */
  @Override public void setTransferFiles (FileTransferMode mode) throws DrmaaException {
    ((RemoteTemplate) remote.get (url).get (RemoteTemplate.class)).setTransferFiles (template, mode);
  }

  /* (non-Javadoc)
   * @see org.ggf.drmaa.JobTemplate#getTransferFiles()
   */
  @Override public FileTransferMode getTransferFiles () throws DrmaaException {
    return ((RemoteTemplate) remote.get (url).get (RemoteTemplate.class)).getTransferFiles (template);
  }

  /* (non-Javadoc)
   * @see org.ggf.drmaa.JobTemplate#setDeadlineTime(org.ggf.drmaa.PartialTimestamp)
   */
  @Override public void setDeadlineTime (PartialTimestamp deadline) throws DrmaaException {
    ((RemoteTemplate) remote.get (url).get (RemoteTemplate.class)).setDeadlineTime (template, deadline);
  }

  /* (non-Javadoc)
   * @see org.ggf.drmaa.JobTemplate#getDeadlineTime()
   */
  @Override public PartialTimestamp getDeadlineTime () throws DrmaaException {
    return ((RemoteTemplate) remote.get (url).get (RemoteTemplate.class)).getDeadlineTime (template);
  }

  /* (non-Javadoc)
   * @see org.ggf.drmaa.JobTemplate#setHardWallclockTimeLimit(long)
   */
  @Override public void setHardWallclockTimeLimit (long hardWallclockLimit) throws DrmaaException {
    ((RemoteTemplate) remote.get (url).get (RemoteTemplate.class)).setHardWallclockLimit (template, hardWallclockLimit);
  }

  /* (non-Javadoc)
   * @see org.ggf.drmaa.JobTemplate#getHardWallclockTimeLimit()
   */
  @Override public long getHardWallclockTimeLimit () throws DrmaaException {
    return ((RemoteTemplate) remote.get (url).get (RemoteTemplate.class)).getHardWallclockLimit (template);
  }

  /* (non-Javadoc)
   * @see org.ggf.drmaa.JobTemplate#setSoftWallclockTimeLimit(long)
   */
  @Override public void setSoftWallclockTimeLimit (long softWallclockLimit) throws DrmaaException {
    ((RemoteTemplate) remote.get (url).get (RemoteTemplate.class)).setSoftWallclockLimit (template, softWallclockLimit);
  }

  /* (non-Javadoc)
   * @see org.ggf.drmaa.JobTemplate#getSoftWallclockTimeLimit()
   */
  @Override public long getSoftWallclockTimeLimit () throws DrmaaException {
    return ((RemoteTemplate) remote.get (url).get (RemoteTemplate.class)).getSoftWallclockLimit (template);
  }

  /* (non-Javadoc)
   * @see org.ggf.drmaa.JobTemplate#setHardRunDurationLimit(long)
   */
  @Override public void setHardRunDurationLimit (long hardRunLimit) throws DrmaaException {
    ((RemoteTemplate) remote.get (url).get (RemoteTemplate.class)).setHardRunDurationLimit (template, hardRunLimit);
  }

  /* (non-Javadoc)
   * @see org.ggf.drmaa.JobTemplate#getHardRunDurationLimit()
   */
  @Override public long getHardRunDurationLimit () throws DrmaaException {
    return ((RemoteTemplate) remote.get (url).get (RemoteTemplate.class)).getHardRunDurationLimit (template);
  }

  /* (non-Javadoc)
   * @see org.ggf.drmaa.JobTemplate#setSoftRunDurationLimit(long)
   */
  @Override public void setSoftRunDurationLimit (long softRunLimit) throws DrmaaException {
    ((RemoteTemplate) remote.get (url).get (RemoteTemplate.class)).setSoftRunDurationLimit (template, softRunLimit);
  }

  /* (non-Javadoc)
   * @see org.ggf.drmaa.JobTemplate#getSoftRunDurationLimit()
   */
  @Override public long getSoftRunDurationLimit () throws DrmaaException {
    return ((RemoteTemplate) remote.get (url).get (RemoteTemplate.class)).getSoftRunDurationLimit (template);
  }

  /* (non-Javadoc)
   * @see org.ggf.drmaa.JobTemplate#getAttributeNames()
   */
  @SuppressWarnings ("rawtypes") @Override public Set getAttributeNames () throws DrmaaException {
    return ((RemoteTemplate) remote.get (url).get (RemoteTemplate.class)).getAttributeName (template);
  }
}
